package cn.zn.modules.budget.his.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.zn.modules.budget.his.entity.BudgetInfoFreezs;
import cn.zn.modules.budget.his.entity.QBudgetInfoFreezs;
import cn.zn.modules.budget.his.entity.vo.BudgetInfoFreezsVO;
import cn.zn.modules.budget.his.repository.BudgetInfoFreezsRepository;
import cn.zn.modules.budget.his.service.BudgetInfoFreezsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service
public class BudgetInfoFreezsServiceImpl implements BudgetInfoFreezsService {

    @Autowired
    private BudgetInfoFreezsRepository budgetInfoFreezsRepository;

    @Override
    public List<BudgetInfoFreezsVO> findFreezs(String sumId) {
        QBudgetInfoFreezs qBudgetInfoFreezs = QBudgetInfoFreezs.budgetInfoFreezs;
        Iterator<BudgetInfoFreezs> budgetInfoFreezsIterator = budgetInfoFreezsRepository.findAll(qBudgetInfoFreezs.sumId.eq(sumId)).iterator();
        List<BudgetInfoFreezsVO> budgetInfoFreezsVOS = CollUtil.newArrayList();
        BudgetInfoFreezsVO budgetInfoFreezsVO;
        while (budgetInfoFreezsIterator.hasNext()) {
            BudgetInfoFreezs budgetInfoFreezs = budgetInfoFreezsIterator.next();
            budgetInfoFreezsVO = new BudgetInfoFreezsVO();
            BeanUtils.copyProperties(budgetInfoFreezs, budgetInfoFreezsVO);
            budgetInfoFreezsVOS.add(budgetInfoFreezsVO);
        }
        return budgetInfoFreezsVOS;
    }
}
